<!--
 * @Descripttion: 
 * @version: 
 * @Author: Jun
 * @Date: 2021-05-24 14:57:39
 * @LastEditors: Jun
 * @LastEditTime: 2021-06-10 15:41:23
-->
<template>
  <div class="signup page">
    <!-- 导航条 -->
    <nav-bar></nav-bar>

    <div class="container">
      <!-- 表格 -->
      <my-table class="table" :tableData="tableData" :propArray="propArray">
        <template v-slot="{ data }">
          <el-button v-if="data.state === '审核通过'" type="primary" size="small" @click="goToPay(data)">缴费</el-button>

          <el-button v-if="data.state === '已出准考证'" type="primary" size="small" @click="zkz(data)">打印准考证</el-button>

          <el-button v-if="data.state === '已出证书'" type="primary" size="small" @click="zs(data)">打印证书</el-button>
        </template>
      </my-table>

      <!-- 分页 -->
      <pagination :total="total" v-model="currentPage"></pagination>
    </div>
  </div>
</template>

<script>
import { listUrl } from "api/userInfo.js";
import {baseURL} from "utils/common.js"
export default {
  data() {
    return {
      tableData: [],
      propArray: [
        {
          //表单标题
          label: "考试名称",
          prop: "ename",
        },
        {
          label: "考试时间",
          prop: "eemtm",
        },
        {
          label: "准考证号", //
          prop: "zkh",
        },
        {
          label: "考试费",
          prop: "ecost",
        },
        {
          label: "报名开始时间",
          prop: "estar",
        },
        {
          label: "报名截止时间",
          prop: "eddle",
        },
        {
          label: "缴费时间",
          prop: "pytm",
        },
        {
          label: "考生得分",
          prop: "score",
        },
        {
          label: "通过情况",
          prop: "statn",
        },
        {
          label: "状态",
          prop: "state",
        },
        {
          label: "审核结果",
          prop: "reason",
        },
      ],
      currentPage: 1, //当前页数
      total:0//总条数
    };
  },
  methods: {
    API_list(current) {
      return this.$httpRequest({
        url: listUrl,
        method: "POST",
        data: {
          page: {
            current: current,
            size: 10,
          },
          param: {},
        },
      });
    },
    goToPay(data) {//去支付页
      this.$router.push({path:"/pay",query:{id:data.id}})
    },
    zkz(data){//下载准考证
      window.location.href = baseURL + data.admission
    },
    zs(data){//下载证书
      window.location.href = baseURL + data.qualification
    },
    filterState(array){
      array.forEach((item)=>{
        if(item.state === 1){
          item.state = "待审核"
        }else if(item.state === 2){
          item.state = "审核通过"
        }else if(item.state === 3){
          item.state = "审核不通过"
        }else if(item.state === 4){
          item.state = "已缴费"
        }else if(item.state === 5){
          item.state = "已出准考证"
        }else if(item.state === 6){
          item.state = "已出证书"
        }
      })
      return array
    }
  },
  async created() {
    let res = await this.API_list(this.currentPage);
    let { total, current, records } = res.data.data;
    this.total = total;
    this.currentPage = current;
    this.tableData = this.filterState(records);
  },
};
</script>

<style>
</style>